<template>
	<view class="page">
		<z-paging ref="paging" v-model="dataList" @query="queryList">
			<template #top>
				<u-navbar title="我的订单" safeAreaInsetTop fixed placeholder :isBack="false" :border-bottom="false"></u-navbar>
				<view style="padding: 24rpx;background: #fff;border-bottom: solid 1px #f2f2f2;">
					<u-tabs :list="tabList" :current="tabIndex" @change="changeTab"></u-tabs>
				</view>
			</template>
			
			<!-- 列表 -->
			<view style="background: #fff;">
				<view style="padding: 24rpx 32rpx 0 32rpx;margin-bottom: 20rpx;" v-for="(item, index) in dataList" :key="index"
				@click="jumpTo('/pages/order/detail?order_id=' + item.id)">
					<view style="border-bottom: #f2f2f2 solid 1px;padding-bottom: 24rpx;">
						
						<view style="display: flex;align-items: center;justify-content: space-between;">
							<view style="color: #999;">{{item.order_sn}}</view>
							<view style="color: #ff9900;">待服务</view>
						</view>
						<view style="margin-top: 16rpx;">
							<view style="display: flex;align-items: center;">
								<view style="width: 20rpx;height: 20rpx;background: #333;border-radius: 50%;"></view>
								<view style="flex: 1;margin-left: 20rpx;">
									<view style="font-weight: bold;font-size: 30rpx;">{{item.gigjobs_name}}</view>
									<view style="color: #999;margin-top: 10rpx;">
										<text v-for="(it, ind) in item.masterData" :key="ind" 
										style="padding-right: 24rpx;font-size: 26rpx;">{{it.master_name}}</text>
									</view>
								</view>
							</view>
							<view style="margin-top: 16rpx;display: flex;align-items: center;">
								<view style="width: 20rpx;height: 20rpx;background: #0daff0;border-radius: 50%;"></view>
								<view style="flex: 1;margin-left: 20rpx;">
									<view style="font-weight: bold;font-size: 30rpx;
									width: 300px;
									overflow: hidden;
									text-overflow: ellipsis;
									white-space: nowrap;">{{item.location_detail}}</view>
									<view style="color: #999;font-size: 26rpx;margin-top: 10rpx;">
										<text>{{item.nickname}}</text>
										<text style="padding-left: 24rpx;">{{item.mobile}}</text>
									</view>
								</view>
							</view>
						</view>
						<view style="font-size: 28rpx;margin-top: 16rpx;display: flex;align-items: center;justify-content: space-between;">
							<view style="color: #ff9900;font-weight: bold;font-size: 32rpx;">￥{{item.total_price}}</view>
							<view style="display: flex;align-items: center;" class="button-group">
								<view class="hollowcss" @click.stop="toggleTagSelect(item)">联系师傅</view>
								<!-- <view style="color: #909399;border: 2rpx solid #909399;
								border-radius: 10rpx;padding: 16rpx 0rpx;width: 80px;
								text-align: center;margin-left: 24rpx;" @click="toggleTagSelect(item)">删除订单</view> -->
								<!-- <view style="color: #909399;border: 2rpx solid #909399;
								border-radius: 10rpx;padding: 16rpx 0rpx;width: 80px;
								text-align: center;margin-left: 24rpx;" @click="toggleTagSelect(item)">查看师傅</view> -->
								<!-- <view style="color: #909399;border: 2rpx solid #909399;
								border-radius: 10rpx;padding: 16rpx 0rpx;width: 80px;
								text-align: center;margin-left: 24rpx;" @click="toggleTagSelect(item)">退款</view> -->
								<!-- <view style="color: #fff;border: 2rpx solid #ff9900;background: #ff9900;
								border-radius: 10rpx;padding: 16rpx 0rpx;width: 80px;
								text-align: center;margin-left: 24rpx;" @click="toggleTagSelect(item)">催付款</view> -->
								<view class="solidcss" v-if="item.order_status == 0 && item.total_price > 0" @click.stop="goPay(item)">支付</view>
								<view class="solidcss" v-if="item.order_status == 6" @click.stop="goPayAmount(item)">支付尾款</view>
								<!-- <view class="solidcss" v-if="item.order_status == 1" @click="goPay(item)">增加附加</view> -->
								<!-- <view style="color: #fff;border: 2rpx solid #0daff0;background: #0daff0;
								border-radius: 10rpx;padding: 16rpx 0rpx;width: 80px;
								text-align: center;margin-left: 24rpx;" @click="toggleTagSelect(item)">去报价</view> -->
								<!-- <view class="solidcss" v-if="item.order_status == 13" @click="assignMaster(item)">分配师傅</view> -->
								<!-- <view style="color: #fff;border: 2rpx solid #0daff0;background: #0daff0;
								border-radius: 10rpx;padding: 16rpx 0rpx;width: 80px;
								text-align: center;margin-left: 24rpx;" @click="toggleTagSelect(item)">提醒评价</view> -->
								<!-- <view style="color: #fff;border: 2rpx solid #0daff0;background: #0daff0;
								border-radius: 10rpx;padding: 16rpx 0rpx;width: 80px;
								text-align: center;margin-left: 24rpx;" @click="toggleTagSelect(item)">反馈平台</view> -->
							</view>
						</view>
						
					</view>
				</view>
			</view>
			
			<template #bottom>
				<view class="footer">
					<button class="confirm-btn" @click="confirmSelection" style="background: #1877f2;color: #fff;">确定</button>
				</view>
			</template>
		</z-paging>
		
		<u-toast ref="uToast" />
		
		<view style="height: 200rpx;"></view>
		
		<!-- <view style="position: fixed;right: 32rpx;bottom: 204rpx;" @click="jumpTo('/pages/prescription/ordinaryEdit')">
			<image src="@/static/img/add.png" mode="widthFix" style="width: 80rpx;"></image>
		</view> -->
		<!-- 更多操作 -->
		<u-action-sheet :list="moreList" v-model="moreShow" border-radius="32"
		@click="moreClick"></u-action-sheet>
		
		
		<u-tabbar v-model="current" :list="tabbar" active-color="#0daff0"  :mid-button="true"></u-tabbar>
	</view>
</template>

<script>
	import { getTabbarConfig } from '@/common/tabbar';
	import { request } from 'utils/request.js';
	export default {
		data() {
			return {
				current: 1,
				tabbar: getTabbarConfig(true),
				
				dataList: [],
				keyword:'',
				
				tabIndex: 0,
				tabList: [{
						name: '全部',
						filter: 'all'
					},
					{
						name: '定金待付',
						filter: 'deposit'
					},
					{
						name: '等待接单',
						filter: 'isnotb'
					},
					{
						name: '等待派单',
						filter: 'amount'
					},
					// {name: '等待派单', filter: 'isnotm'},
					{
						name: '等待上门',
						filter: 'service'
					},
					{
						name: '已完成',
						filter: 'completed'
					},
					{
						name: '维权',
						filter: 'maintanance'
					},
				] 
				
			};
		},
		onLoad(options) {
			// 刷新页面
			uni.$on('htmlRefresh', (options) => {
				console.log('子页面---->>>>>>', options);
				this.$refs.paging.reload()//重置
			})
		    // 从父页面传递的已选标签
		    if (options.selected) {
				this.selectedTags = JSON.parse(options.selected);
		    }
		    // this.filteredTags = [...this.allTags];
		},
		methods: {
			goPay(item){
				console.log('item: ', item);
				uni.navigateTo({
					url: "/pages/pay/payment?orderId=" + item.id,
				});
			},
			goPayAmount(item){
				console.log('item: ', item);
				uni.navigateTo({
					url: "/pages/pay/paymentAmount?orderId=" + item.id,
				});
			},
			changeTab(index) {
				console.log('tabIndex： ', index)
				this.tabIndex = index;
				// uni.$emit('refreshOrder', this.tabList[this.tabIndex].filter);
			},
			// 搜索标签
			onSearch() {
				this.$refs.paging.reload()//重置
			},
			// 切换标签选择状态
			toggleTagSelect(tag) {
				const index = this.selectedTags.findIndex(t => t.id === tag.id);
				if (index >= 0) {
					// 已选中，取消选择
					this.selectedTags.splice(index, 1);
				} else {
					// 未选中，添加到已选
					this.selectedTags.push(tag);
				}
			},
			// 确认选择
			confirmSelection() {
				// 保存到本地存储
				// uni.setStorageSync('selectedTags', JSON.stringify(this.selectedTags));
				let selectedTagsJson = JSON.stringify(this.selectedTags);
				// 返回上一页
				setTimeout(() => {
					uni.navigateBack();
					uni.$emit('htmlRefresh', {selectedTagsJson: selectedTagsJson});
				}, 600);
				// uni.navigateBack();
			},
			moreClick(e){
				console.log(e)
			},
			// 获取列表
			queryList(pageNo, pageSize) {
				
				let params = {};
				params.page = pageNo;
				params.keyword = this.keyword;
				request.getWithToken({
					url: '/order/orderLis',
					data: params
				}).then(res=>{
					// console.log(res)
					this.$refs.paging.complete(res.data.dataList);
					// this.filteredTags = [...res.data];
					// this.$refs.paging.complete(this.filteredTags);
				})
			},
			followClick(e){
				let talkData = uni.getStorageSync('talkData');
				
			},
			jumpTo(path){
				uni.navigateTo({
					url: path
				})
			},
			onSubmitSave(){
				uni.navigateTo({
					url: '/pages/prescription/selectMedicine'
				})
			}
		}
	}
</script>

<style>
	page{
		background-color: #f2f2f2 !important;
	}
</style>
<style lang="scss" scoped>
	.button-group {
		margin: 10rpx 0;
		display: flex;
		justify-content: flex-end;
		margin-top: 30rpx;
	
		.item-btn {
			align-self: center;
			display: flex;
			justify-content: center;
			align-items: center;
			margin: 0;
			padding: 0 20rpx;
			height: 56rpx;
			border: 1px solid #888;
			border-radius: 10rpx;
			color: #888;
			font-size: 26rpx;
	
			&+.item-btn {
				margin-left: 22rpx;
			}
	
			&.primary {
				color: #FFF;
				border: 1px solid #fb7601;
				background-color: #fb7601;
			}
		}
	}
	
	.solidcss{
		color: #fff;border: 2rpx solid #0daff0;background: #0daff0;
		border-radius: 10rpx;padding: 16rpx 0rpx;width: 80px;
		text-align: center;margin-left: 24rpx;
	}
	.hollowcss{
		color: #909399;border: 2rpx solid #909399;
		border-radius: 10rpx;padding: 16rpx 0rpx;width: 80px;
		text-align: center;margin-left: 24rpx;
	}
</style>
